fix(extension): return structured errors instead of throwing in command handlers#319
Closed
margaretjgu wants to merge 22 commits into
Closed
fix(extension): return structured errors instead of throwing in command handlers#319margaretjgu wants to merge 22 commits into
margaretjgu wants to merge 22 commits into
Conversation
…2e testing" This reverts commit e0f1fae.
…nto fix/extension-handler-errors
…nd handlers
installExtension, uninstallExtension, upgradeExtension, and searchExtensions
can throw on invalid input or missing extensions. The factory only converts
{ error: { code } } return values to clean user-facing messages -- unhandled
throws produce a raw Node.js stack trace.
Wrap all four handler functions in try-catch and return handlerError() so
errors are displayed as 'Error: <message>' with a non-zero exit code rather
than crashing with a full stack trace.
Fixes #312
❌MegaLinter analysis: Error
Detailed Issues❌ TYPESCRIPT / eslint - 2 errorsSee detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #312.
installExtension,uninstallExtension,upgradeExtension, andsearchExtensionscan throw on invalid input (bad source string, extension not found, network error). The factory only converts{ error: { code } }return values to clean user-facing messages -- unhandled throws produced a raw Node.js stack trace.Before:
After:
Changes
src/extension/register.ts: added ahandlerError()helper and wrappedhandleInstall,handleRemove,handleUpgrade, andhandleSearchin try-catch blocks that return structured{ error: { code, message } }objectstest/extension/register.test.ts: new test file covering the error-handling paths for install (bad source), upgrade (not installed), and confirming no stack traces leak to stderrNote
This branch is based on
feat/extension-search-upgrade(PR #304) since the extension files are not yet onmain. It should be merged after the extension chain lands.Test plan
returns structured error for invalid source instead of throwing-- newreturns structured error for bad github: prefix-- newreturns structured error for bare single-segment source-- newreturns structured error when named extension is not installed-- new